package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.BatchDeleteRequest;
import com.mes.cloud.api.dto.request.employee.*;
import com.mes.cloud.api.dto.request.position.*;
import com.mes.cloud.api.dto.response.CompartmentByEmployeeDto;
import com.mes.cloud.api.dto.response.employee.PositionListDto;
import com.mes.cloud.api.dto.response.employee.SysEmployeePositionBusinessDto;
import com.mes.cloud.api.dto.response.employee.SysEmployeePositionDto;
import com.mes.cloud.api.dto.response.position.AuthorisationTypeDto;
import com.mes.cloud.api.dto.response.position.SysPositionEmployeePageDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysEmployeePositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xy
 * @version 2019-08-02 14:28:28
 * @email yuan.xue3@pactera.com
 */
@Api(tags = "员工岗位", value = "员工岗位接口")
@RestController
@RequestMapping(value = "/sysEmployeePosition")
public class SysEmployeePositionController  {

    private SysEmployeePositionService sysEmployeePositionService;

    @Autowired
    public SysEmployeePositionController(SysEmployeePositionService sysEmployeePositionService) {
        this.sysEmployeePositionService = sysEmployeePositionService;
    }
    /**
     * 描述  员工查看岗位列表
     *
     * @param positionPageListRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult<com.shinho.tntframe.core.common.model.CommPager<com.shinho.crm.base.api.dto.response.employee.PositionListDto>>
     * @author 郑样平
     * @date 2019/8/7 11:38
     */
    @ApiOperation(value = "员工界面查看岗位列表", notes = "员工界面查看岗位列表")
    @PostMapping(value = "/positionPageList")
    public JsonResult<CommPager<PositionListDto>> positionPageList(@RequestBody PositionPageListRequest positionPageListRequest) {
        return sysEmployeePositionService.positionPageList(positionPageListRequest);
    }

    /**
     * 获取员工所有岗位
     * @param positionListRequest
     * @return
     */
    @ApiOperation(value = "获取员工所有岗位", notes = "获取员工所有岗位")
    @PostMapping(value = "/positionList")
    public JsonResult<List<PositionListDto>> positionList(@Valid @RequestBody PositionListRequest positionListRequest) {
        return sysEmployeePositionService.positionList(positionListRequest);
    }

    /**
     * 描述  员工添加岗位
     *
     * @param bindPositionRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author 郑样平
     * @date 2019/8/7 10:43
     */
    @ApiOperation(value = "员工添加岗位", notes = "员工添加岗位")
    @PostMapping(value = "/bindPosition")
    public JsonResult bindPosition(@RequestBody BindPositionRequest bindPositionRequest) {
        return sysEmployeePositionService.bindPosition(bindPositionRequest);
    }

    /**
     * 描述 批量移除岗位关联关系
     *
     * @param batchDeleteRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author 郑样平
     * @date 2019/8/7 11:28
     */
    @ApiOperation(value = "批量移除岗位关联关系", notes = "批量移除岗位关联关系")
    @PostMapping(value = "/batchDelete")
    public JsonResult batchDelete(@RequestBody BatchDeleteRequest batchDeleteRequest) {
        return sysEmployeePositionService.batchDelete(batchDeleteRequest);
    }

    /**
     * 描述 是否主要岗位
     *
     * @param employeeIsMainPositionRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author 郑样平
     * @date 2019/8/7 12:52
     */
    @ApiOperation(value = "是否主岗位", notes = "是否主岗位")
    @PostMapping(value = "/isMainPosition")
    public JsonResult isMainPosition(@RequestBody EmployeeIsMainPositionRequest employeeIsMainPositionRequest) {
        return sysEmployeePositionService.isMainPosition(employeeIsMainPositionRequest);
    }

    @ApiOperation(value = "用户岗位分页查询", notes = "用户岗位分页查询")
    @PostMapping(value = "/positionEmployeePageList")
    public JsonResult<CommPager<SysPositionEmployeePageDto>> positionEmployeePageList(@RequestBody SysPositionEmployeePageRequest sysPositionEmployeePageRequest) {
        return sysEmployeePositionService.positionEmployeePageList(sysPositionEmployeePageRequest);
    }

    @ApiOperation(value = "岗位关联员工", notes = "岗位关联员工")
    @PostMapping(value = "/positionRelationEmployee")
    public JsonResult positionRelationEmployee(@RequestBody RelationEmployeeRequest relationEmployeeRequest) {
        return sysEmployeePositionService.positionRelationEmployee(relationEmployeeRequest);
    }

    @ApiOperation(value = "岗位移除关联员工", notes = "岗位移除关联员工")
    @PostMapping(value = "/positionRemoveRelationEmployee")
    public JsonResult positionRemoveRelationEmployee(@RequestBody RelationEmployeeRequest relationEmployeeRequest) {
        return sysEmployeePositionService.positionRemoveRelationEmployee(relationEmployeeRequest);
    }

    /**
     * <岗位员工更新授权方式>
     * @author xy
     * @date   2019/8/12 11:34
     * @param  sysEmployeePositionRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult
     */
    @ApiOperation(value = "岗位员工更新授权方式", notes = "岗位员工更新授权方式")
    @PostMapping(value = "/positionEmployeeUpdateAuthType")
    public JsonResult positionEmployeeUpdateAuthType(@RequestBody SysEmployeePositionRequest sysEmployeePositionRequest) {
        return sysEmployeePositionService.positionEmployeeUpdateAuthType(sysEmployeePositionRequest);
    }

    /**
     * 同步信息-增加
     * @param synchroPositionEmployeeAddRequest
     * @return
     */
    @ApiOperation(value = "同步信息-增加", notes = "同步信息-增加")
    @PostMapping(value = "/synchroAdd")
    public JsonResult synchroAdd(@RequestBody SynchroPositionEmployeeAddRequest synchroPositionEmployeeAddRequest) {
        return sysEmployeePositionService.synchroAdd(synchroPositionEmployeeAddRequest);
    }

    /**
     * 同步信息-更新
     * @param synchroPositionEmployeeUpdateByPositionIdAndEmployeeIdRequest
     * @return
     */
    @ApiOperation(value = "同步信息-更新", notes = "同步信息-更新")
    @PostMapping(value = "/updateByPositionIdAndEmployeeId")
    public JsonResult updateByPositionIdAndEmployeeId(@RequestBody SynchroPositionEmployeeUpdateByPositionIdAndEmployeeIdRequest synchroPositionEmployeeUpdateByPositionIdAndEmployeeIdRequest) {
        return sysEmployeePositionService.updateByPositionIdAndEmployeeId(synchroPositionEmployeeUpdateByPositionIdAndEmployeeIdRequest);
    }

    /**
     * 同步信息-记录数
     * @param synchroPositionEmployeeCountByPositionIdAndEmployeeIdRequest
     * @return
     */
    @ApiOperation(value = "同步信息-记录数", notes = "同步信息-记录数")
    @PostMapping(value = "/synchroCountByPositionIdAndEmployeeId")
    public JsonResult synchroCountByPositionIdAndEmployeeId(@RequestBody SynchroPositionEmployeeCountByPositionIdAndEmployeeIdRequest synchroPositionEmployeeCountByPositionIdAndEmployeeIdRequest) {
        return sysEmployeePositionService.synchroCountByPositionIdAndEmployeeId(synchroPositionEmployeeCountByPositionIdAndEmployeeIdRequest);
    }

    /**
     * <查询岗位员工列表>
     * @author xy
     * @date   2019/9/9 14:26
     * @return com.shinho.tntframe.core.common.model.JsonResult<java.util.List<com.shinho.crm.base.api.dto.response.employee.SysEmployeePositionDto>>
     */
    @ApiOperation(value = "查询岗位员工列表", notes = "查询岗位员工列表")
    @PostMapping(value = "/getPositionIdList")
    public JsonResult<List<SysEmployeePositionDto>> getPositionIdList() {
        return sysEmployeePositionService.getPositionIdList();
    }

    @ApiOperation(value = "根据岗位查询", notes = "根据岗位查询")
    @PostMapping(value = "/getEmployeeByPositionId")
    public JsonResult<List<SysEmployeePositionBusinessDto>> getEmployeeByPositionId(@Valid @RequestBody SysEmployeePositionBusinessRequest req) {
        return sysEmployeePositionService.getEmployeeByPositionId(req);
    }

    @ApiOperation(value = "查询当前岗所有上级岗位及岗位人员", notes = "查询当前岗所有上级岗位及岗位人员")
    @PostMapping(value = "/getAllParentEmployeeByPositionId")
    public JsonResult<List<SysEmployeePositionBusinessDto>> getAllParentEmployeeByPositionId(@Valid @RequestBody SysEmployeePositionBusinessRequest req) {
        return sysEmployeePositionService.getAllParentEmployeeByPositionId(req);
    }

    @ApiOperation(value = "查询当前岗所有下级岗位及岗位人员", notes = "查询当前岗所有下级岗位及岗位人员")
    @PostMapping(value = "/getChildrenEmployeeByPositionId")
    public JsonResult<List<SysEmployeePositionBusinessDto>> getChildrenEmployeeByPositionId(@Valid @RequestBody SysEmployeePositionBusinessRequest req) {
        return sysEmployeePositionService.getChildrenEmployeeByPositionId(req);
    }

    @ApiOperation(value = "果岗位下有多个员工 只取第一个 做为业务代表的主要员工", notes = "果岗位下有多个员工 只取第一个 做为业务代表的主要员工")
    @ApiImplicitParam(paramType = "String", name = "positionId", value = "主要岗位ID", required = true)
    @GetMapping(value = "/getCompartmentByEmployee/{positionId}")
    public JsonResult<CompartmentByEmployeeDto> getCompartmentByEmployee(@PathVariable String positionId) {
        return sysEmployeePositionService.getCompartmentByEmployee(positionId);
    }

    @ApiOperation(value = "通过员工岗位查询", notes = "通过员工岗位查询")
    @PostMapping(value = "/queryPositionList")
    public JsonResult<List<PositionListDto>> queryPositionList(@RequestBody List<String> positionIds) {
        return sysEmployeePositionService.queryPositionList(positionIds);
    }

    @ApiOperation(value = "当前登录人，个人授权，组织授权", notes = "当前登录人，个人授权，组织授权")
    @GetMapping(value = "/getAuthorisationType")
    public JsonResult<AuthorisationTypeDto> getAuthorisationType() {
        return sysEmployeePositionService.getAuthorisationType();
    }
}
